﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="RoleMemberListCtrl.ascx.cs" Inherits="DMS.Web.Common.Controls.RoleMemberListCtrl" %>
<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="diy" %>
<%@ Register Src="Loading.ascx" TagName="Loading" TagPrefix="uc1" %>
<style type="text/css">
    #chkSelector, #radSelector
    {
        border-width: 0px;
    }
</style>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <%--搜索栏--%>
        <div class="search" style="display:block;">
            <!----------- 查询信息 ------------------>
            <table width="100%" cellpadding="0" cellspacing="0">
                <tr>
                    <td class="ico">
                        <a href="javascript:changeView('1')" style="display:none;">
                            <img src="/themes/default/ico_have.gif" id="ico_1" border="0"></a>
                    </td>
                    <td class="form">
                        <table cellpadding="0" cellspacing="0" width="100%">
                            <tr>
                                <th>
                                    <nobr>
                                        成员名称：
                                    </nobr>
                                </th>
                                <td>
                                    <asp:TextBox ID="txtActorName" runat="server" Width="80px"></asp:TextBox>
                                </td>
                                <th>
                                    <nobr>
                                        所在部门：
                                    </nobr>
                                </th>
                                <td>
                                    <asp:TextBox ID="DeptName" runat="server" Width="80px"></asp:TextBox>
                                </td>
                                <th style="display: none">
                                    <nobr>
                                        成员类型：
                                    </nobr>
                                </th>
                                <td>
                                    <asp:DropDownList ID="ddlActorType" runat="server" Visible="False">
                                        <asp:ListItem Value="" Selected="True">全部</asp:ListItem>
                                        <asp:ListItem Value="User">内部用户</asp:ListItem>
                                        <asp:ListItem Value="Dept">组织部门</asp:ListItem>
                                        <asp:ListItem Value="SupplierAccount">第三方人员</asp:ListItem>
                                    </asp:DropDownList>
                                </td>                                
                                <th>
                                    <asp:HiddenField ID="hidRoleID" runat="server" />
                                    <asp:HiddenField ID="hidRoleName" runat="server" />
                                </th>
                                <td class="button">
                                    <nobr>
                                        <asp:LinkButton ID="btnQuery" CssClass="linkbtn" runat="server" OnClientClick="javascript:return CheckQueryCondition(this);" OnClick="btnQuery_Click"><span>查询</span></asp:LinkButton>
                                        <asp:LinkButton ID="lbtnAddMember" CssClass="linkbtn" runat="server" OnClientClick="javascript:return AddRoleMember(this);" OnClick="lbtnAddMember_Click" CanDisplay="Management"><span>新增</span></asp:LinkButton>
                                        <asp:LinkButton ID="lbtnExport" CssClass="linkbtn" runat="server" OnClick="lbtnExport_Click" CanDisplay="Management"><span>导出</span></asp:LinkButton>
                                        <asp:HiddenField ID="hidNewMemberIDs" runat="server" />
                                        <asp:HiddenField ID="hidNewMemberTypes" runat="server" />
                                    </nobr>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
        </div>
        <%--数据列表--%>
        <asp:DataGrid ID="dgRoleList" runat="server" AutoGenerateColumns="false" Width="100%"
            CssClass="dg_borderstyle" OnItemDataBound="dgRoleList_ItemDataBound" OnItemCommand="dgRoleList_ItemCommand">
            <HeaderStyle HorizontalAlign="Center" />
            <ItemStyle CssClass="dg_itemstyle" />
            <AlternatingItemStyle CssClass="dg_alternatingitemstyle" />
            <Columns>
                <asp:TemplateColumn HeaderText="多选" Visible="false">
                    <ItemStyle Width="30px" HorizontalAlign="Center" />
                    <HeaderTemplate>
                        <a id="selectAllLink" href="javascript:" title="点击“全选”或“取消全选”" onclick="javascrpt:SelectAll(this, 'chkSelector');"
                            statue="false" style="cursor: pointer;">全选</a>
                    </HeaderTemplate>
                    <ItemTemplate>
                        <input type="checkbox" id="chkSelector" name="chkSelector" value="<%#Eval("ID") %>" onchange="javascript:return;UpdateChkStatue(this, 'selectAllLink');" />
                    </ItemTemplate>
                </asp:TemplateColumn>
                <asp:TemplateColumn HeaderText="单选" Visible="false">
                    <ItemStyle Width="30px" HorizontalAlign="Center" />
                    <HeaderTemplate>
                        选择
                    </HeaderTemplate>
                    <ItemTemplate>
                        <input type="radio" id="radSelector" name="radSelector" value="<%#Eval("ID") %>" onclick="javascript:Clear();AddItem('<%#Eval("Name") %><asp:Literal ID="ltlNameRemark" runat="server"></asp:Literal>','<Actor Type=\'<%#Eval("ActorType") %>\' ID=\'<%#Eval("ID") %>\' Name=\'<%#Eval("Name") %>\' />');" />
                        
                    </ItemTemplate>
                </asp:TemplateColumn>
                <asp:TemplateColumn HeaderText="类型">
                    <ItemStyle Width="100px" HorizontalAlign="Center" />
                    <ItemTemplate>
                        <asp:Label ID="lblActorType" runat="server"></asp:Label>
                    </ItemTemplate>
                </asp:TemplateColumn>
                <asp:TemplateColumn HeaderText="名称">
                    <ItemStyle Width="150px" />
                    <ItemTemplate>
                        <div title="<%#Eval("Name") %>" style="overflow: hidden; text-overflow: ellipsis; width: 150px;">
                            <nobr>
                                <%#Eval("Name") %><asp:Literal ID="ltlLoginID" runat="server"></asp:Literal>
                            </nobr>
                        </div>
                    </ItemTemplate>
                </asp:TemplateColumn>
                <asp:TemplateColumn HeaderText="所在部门">
                    <ItemStyle Width="150px" />
                    <ItemTemplate>
                        <div title="<asp:Literal ID='ltlFullName' runat='server'></asp:Literal>" style="overflow: hidden; text-overflow: ellipsis; width: 150px;">
                            <nobr>
                                <asp:Label ID="lblFullName" runat="server"></asp:Label>
                            </nobr>
                        </div>
                    </ItemTemplate>
                </asp:TemplateColumn>
                <asp:TemplateColumn HeaderText="管理范围" Visible="False">
                    <ItemStyle Width="150px" />
                    <ItemTemplate>
                        <div style="overflow: hidden; text-overflow: ellipsis; width: 150px;">
                            <nobr>
                                <asp:Label ID="lblScope" runat="server"></asp:Label>
                            </nobr>
                        </div>
                    </ItemTemplate>
                </asp:TemplateColumn>
                <asp:TemplateColumn HeaderText="操作">
                    <ItemTemplate>
                        <nobr>
                            <asp:LinkButton ID="lbtnDelete" runat="server" CommandName="Delete">删除</asp:LinkButton>
                            <%--<asp:LinkButton ID="lbtnSetScope" runat="server" CommandName="SetScope" OnClientClick="return false;">设置管理范围</asp:LinkButton>--%>
                            <asp:HiddenField ID="hidScope" runat="server" />
                        </nobr>
                    </ItemTemplate>
                </asp:TemplateColumn>
                <asp:TemplateColumn HeaderText="操作">
                    <ItemStyle HorizontalAlign="Center" />
                    <ItemTemplate>
                        <nobr>
                            <a id="lkSelectBtn" runat="server" href="javascript:">选择</a>
                        </nobr>
                    </ItemTemplate>
                </asp:TemplateColumn>
            </Columns>
        </asp:DataGrid>
        <diy:AspNetPager ID="pager" runat="server" AlwaysShow="true" OnPageChanged="pager_PageChanged" PageSize="20"
            Width="100%" ShowPageIndexBox="Always" PageIndexBoxType="TextBox" TextBeforePageIndexBox="转到"
            TextAfterPageIndexBox="页" ShowCustomInfoSection="Left" CustomInfoHTML="总数：%RecordCount%，共 %PageCount% 页，当前为第%CurrentPageIndex%页"
            HorizontalAlign="right" FirstPageText="首页" PrevPageText="上页" NextPageText="下页"
            LastPageText="末页" CssClass="dg_pagestyle">
        </diy:AspNetPager>
        <div id="dvEmpty" runat="server" class="EmptyMsg" visible="false">
            没有查询到相应的<asp:Label ID="lblItemTitle" runat="server"></asp:Label>信息。
        </div>
        <asp:ListBox ID="lbGridColState" runat="server" Visible="false">
            <asp:ListItem Value="SingleSelector">1</asp:ListItem>
            <asp:ListItem Value="Management">6</asp:ListItem>
            <asp:ListItem Value="MutilSelector">7</asp:ListItem>
        </asp:ListBox>
    </ContentTemplate>
    <Triggers>
        <asp:PostBackTrigger ControlID="lbtnAddMember" />
        <asp:PostBackTrigger ControlID="lbtnExport" />
    </Triggers>
</asp:UpdatePanel>
<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1"
    DynamicLayout="true">
    <ProgressTemplate>
        <uc1:Loading ID="Loading1" runat="server" />
    </ProgressTemplate>
</asp:UpdateProgress>
<asp:HiddenField ID="hidCmdScope" runat="server" />
<script language="javascript" type="text/javascript">
<!--
    function CheckQueryCondition(obj) {
        return true;
    }

    function AddRoleMember(obj) {
        // 重置
        var newMember = document.getElementById("<%=hidNewMemberIDs.ClientID %>");
        var newMemberType = document.getElementById("<%=hidNewMemberTypes.ClientID %>");
        newMember.value = "";
        newMemberType.value = "";
        // 环境检查
        var contextRoleID = document.getElementById("<%=hidRoleID.ClientID%>").value;
        if (contextRoleID == "") {
            alert("请选择一个分类添加成员。");
            return false;
        }

        // 选择成员
        var sFeature = "dialogHeight:700px; dialogWidth:800px; center:yes; resizable:no; scroll:no; status:no;";
        var url = "/Modules/SystemManagement/Organization/AddRoleMember.aspx?mode=2&rnd=" + Math.random();

        var result = window.showModalDialog(url, null, sFeature);
        if (result) {
            var param = new Object();
            param.userString = result;
            param.method = "Save";
            param.roleId = contextRoleID;
            $.post("/Common/Services/RoleService.aspx", param, saveHandler, "json");
        }

        return true;
    }

    function saveHandler(r) {
//        alert('保存成功');
//        window.location = window.location.href;
    }

    function GetScopes(obj, valHolder) {
        var memberScope = document.getElementById("<%=hidNewMemberTypes.ClientID %>");
        var toSetScope = document.getElementById("<%=hidCmdScope.ClientID %>");
        var valHolderCtrl = document.getElementById(valHolder);
        if (valHolderCtrl == null || toSetScope == null) {
            return;
        }

        // 选择成员
        var res = SelectDepts("MutilSelector", valHolderCtrl.value);
        if (res != null || res == "") {
            var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
            xmlDoc.loadXML(res);
            if (xmlDoc.parseError.errorCode != 0) {
                alert("选择成员后，返回的数据有异常，请联系管理员。");
                return false;
            }

            var doc = xmlDoc.documentElement;
            valHolderCtrl.value = "";
            for (var index = 0; index < doc.childNodes.length; index++) {
                var item = doc.childNodes[index];

                if (item.getAttribute("Type") != "Dept") {
                    continue;
                }

                valHolderCtrl.value += item.getAttribute("ID") + ";";
            }

            toSetScope.value = valHolderCtrl.value;
            return true;
        }
        else {
            return false;
        }
    }
//-->
</script>